home *** CD-ROM | disk | FTP | other *** search
/ Power Bytes: Money & Finance / PowerBytes Money and Finance CD-ROM 01 / PowerBytes Money and Finance CD-ROM 01.iso / Demos / TrueBASIC Demo / User's Guide / Sort < prev    next >
Encoding:
Text File  |  1985-06-20  |  715 b   |  37 lines  |  [TEXT/TRUE]

  1. ! Program to sort text in a list.
  2.  
  3. DIM name$(1)                      ! We'll redim later
  4.  
  5. CALL Get_list                     ! Get list of items 
  6.  
  7. LET n = Ubound(name$)             ! How many we have
  8.  
  9. CALL Sort_list                    ! Sort the list
  10. MAT PRINT name$                   ! Now print sorted list
  11.  
  12. SUB Get_list
  13.  
  14.     PRINT "Enter items to be sorted"
  15.     MAT INPUT name$(?)            ! Redimension to input
  16. END SUB
  17.  
  18. SUB Sort_list
  19.  
  20.     FOR i = n to 2 step -1  
  21.        FOR j = 1 to i-1
  22.           IF name$(j) > name$(j+1) then CALL Swap
  23.        NEXT j
  24.     NEXT i
  25.  
  26. END SUB
  27.  
  28. SUB Swap
  29.  
  30.     LET temp$ = name$(j)          ! Temporary variable
  31.     LET name$(j) = name$(j+1)
  32.     LET name$(j+1) = temp$
  33.  
  34. END SUB
  35.  
  36. END
  37.